
export default function ajax({url, method = 'GET', data = null}) {
  return new Promise((resolve, reject) => {
    fetch(url, {
      method,
      headers: {
        'content-type': 'application/json'
      },
      body: data === null ? null : JSON.stringify(data)
    }).then(res => res.json())
    .then(res => resolve(res))
    .catch(e => reject(e))
  })
}

/*
const ajax = ({url, method = 'GET', data = null}) => {
  return new Promise((resolve, reject) => {
    fetch(url, {
      method,
      headers: {
        'content-type': 'application/json'
      },
      body: data === null ? null : JSON.stringify(data)
    }).then(res => res.json())
    .then(res => resolve(res))
    .catch(e => reject(e))
  })
}*/
